package buildTree;

import util.TreeNode;

/**
 * todo
 *
 * @author: luolidong
 * @create: 2021-07-22 11:03
 * @version: 1.0
 */
public class CreateBinaryTreeByN {
    public TreeNode createTree(int n){
        return create(0, n);
    }
    private TreeNode create(int left,int right){
        if(left>right) return null;
        int val=(left+right)/2;
        TreeNode node = new TreeNode(val);
        node.left=create(left, val-1);
        node.right=create(val+1,right);
        return node;
    }

    public static void main(String[] args) {
        CreateBinaryTreeByN tree = new CreateBinaryTreeByN();
        TreeNode tree1 = tree.createTree(10);
        System.out.println(tree1);
    }
}
